package common;

import interfaces.ITransaction;
import interfaces.IItem;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.SortedSet;
import java.util.ListIterator;


public class TransactionInteger implements ITransaction{
    public List<IItem> items;
    
    public TransactionInteger(){
        items = new LinkedList<IItem>();
    }
    
    public TransactionInteger(int[] items){
        this.items = new ArrayList<IItem>();
        for (int i=0; i<items.length; ++i){
            this.items.add(new ItemInteger(items[i]));
        }
    }
    
    @Override
    public String  toString(){
        StringBuilder sb = new StringBuilder();
        sb.append('{');
        for (IItem i:items){
            sb.append(i.toString());
            sb.append(' ');
        }
        sb.append('}');
        return sb.toString();
    }
    
    @Override 
    public List<IItem> getItems(){
        return items;
    }
    
    @Override
    public void add(IItem item){
        items.add(item);
    }
    
    @Override
    public ITransaction deepcopy(){
        TransactionInteger trans = new TransactionInteger();
        
        ListIterator<IItem> li = items.listIterator();
        while (li.hasNext()){
            trans.items.add(li.next());
        }
        
        return (ITransaction)trans;
    }
    
    @Override
    public ITransaction emptyImplementation(){
        return (ITransaction)(new TransactionInteger());
    }
}
